using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class EditWitkey : Shop, IRequiresSessionState
{
	protected HtmlHead Head1;
	protected ScriptManager ScriptManager1;
	protected HtmlInputHidden HiddenType;
	protected HtmlGenericControl spanWorkType;
	protected DropDownList DropDownList_WitkeyTypeOne;
	protected DropDownList DropDownList_WitkeyTypeTwo;
	protected UpdatePanel UpdatePanel1;
	protected TextBox WitkeyTaskTitle;
	protected TextBox WitkeyContent;
	protected TextBox TextBox_Name;
	protected TextBox TextBox_Email;
	protected TextBox TextBox_Phone;
	protected HtmlTable witkeyTable_3;
	protected DropDownList DropDownList_Mode;
	protected HtmlTable witkeyTable_4;
	protected Button Button_Ok;
	protected HtmlForm form1;
	protected HtmlGenericControl myhtml;
	private DataRow WitkeyInfo;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		if (!base.user.CheckUserLogin())
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotLogin", new string[0]), "Passport/Login.aspx?ComeUrl=" + this.InstallDir + "SaleProduct.aspx");
		}
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkey = shop_Witkey.GetWitkey(Fetch.GetID("ww_Id"));
		if (witkey.Rows.Count > 0 && (int)witkey.Rows[0]["ww_Uid"] == base.user.UserID)
		{
			this.WitkeyInfo = witkey.Rows[0];
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "Member/Index.aspx");
		}
		if (!base.IsPostBack)
		{
			this.Initpage();
		}
	}
	protected void WitkeyTypeTwo()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.DropDownList_WitkeyTypeTwo.DataSource = shop_Witkey.GetWitkeyTypeByTypeFId(int.Parse(this.DropDownList_WitkeyTypeOne.SelectedValue));
		this.DropDownList_WitkeyTypeTwo.DataBind();
	}
	protected void Initpage()
	{
		this.WitkeyTaskTitle.Text = this.WitkeyInfo["ww_Title"].ToString();
		this.WitkeyContent.Text = this.WitkeyInfo["ww_Content"].ToString();
		this.TextBox_Name.Text = this.WitkeyInfo["ww_UserName"].ToString();
		this.TextBox_Email.Text = this.WitkeyInfo["ww_Email"].ToString();
		this.TextBox_Phone.Text = this.WitkeyInfo["ww_Phone"].ToString();
		this.DropDownList_WitkeyTypeOne.Items.FindByText(this.WitkeyInfo["ww_WitkeyTypeOne"].ToString()).Selected = true;
		this.WitkeyTypeTwo();
		this.DropDownList_WitkeyTypeTwo.Items.FindByText(this.WitkeyInfo["ww_WitkeyTypeTwo"].ToString()).Selected = true;
		if (this.WitkeyInfo["ww_Type"].ToString() == "1")
		{
			this.witkeyTable_3.Visible = true;
			this.witkeyTable_4.Visible = true;
			this.HiddenType.Value = "1";
			this.spanWorkType.InnerHtml = "悬赏任务编辑";
			this.DropDownList_Mode.Items.FindByText(this.WitkeyInfo["ww_xsModel"].ToString()).Selected = true;
		}
		else
		{
			this.witkeyTable_3.Visible = false;
			this.witkeyTable_4.Visible = false;
			this.HiddenType.Value = "2";
			this.spanWorkType.InnerHtml = "招标任务编辑";
		}
	}
	protected void DropDownList_WitkeyTypeOne_SelectedIndexChanged(object sender, EventArgs e)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.DropDownList_WitkeyTypeTwo.DataSource = shop_Witkey.GetWitkeyTypeByTypeFId(int.Parse(this.DropDownList_WitkeyTypeOne.SelectedValue));
		this.DropDownList_WitkeyTypeTwo.DataBind();
	}
	public bool CheckInput()
	{
		string value = this.HiddenType.Value;
		string text = string.Empty;
		if (value == "1")
		{
			if (this.DropDownList_WitkeyTypeOne.SelectedValue == "-1")
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyTypeNull") + "<br/>";
			}
			if (this.WitkeyTaskTitle.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyTaskTitleNull") + "<br/>";
			}
			if (this.WitkeyContent.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyContentNull") + "<br/>";
			}
			if (this.TextBox_Name.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/UserNameNull") + "<br/>";
			}
			if (!EditWitkey.IsEmail(this.TextBox_Email.Text))
			{
				text = text + Language.Get("Witkey/WitkeyEmailNull") + "<br/>";
			}
			if (!EditWitkey.IsMobileNum(this.TextBox_Phone.Text))
			{
				text += Language.Get("Witkey/WitkeyPhoneNull");
			}
		}
		else
		{
			if (this.DropDownList_WitkeyTypeOne.SelectedIndex == -1 || this.DropDownList_WitkeyTypeOne.SelectedValue == "-1")
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyTypeNull") + "<br/>";
			}
			if (this.WitkeyTaskTitle.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyTaskTitleNull") + "<br/>";
			}
			if (this.WitkeyContent.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyContentNull") + "<br/>";
			}
			if (this.TextBox_Name.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/UserNameNull") + "<br/>";
			}
			if (!EditWitkey.IsEmail(this.TextBox_Email.Text))
			{
				text = text + Language.Get("Witkey/WitkeyEmailNull") + "<br/>";
			}
			if (!EditWitkey.IsMobileNum(this.TextBox_Phone.Text))
			{
				text += Language.Get("Witkey/WitkeyPhoneNull");
			}
		}
		bool result;
		if (text.Trim().Length > 0)
		{
			this.WriteErrMsg("", text, "");
			result = false;
		}
		else
		{
			result = true;
		}
		return result;
	}
	public static bool IsEmail(string _value)
	{
		Regex regex = new Regex("^\\w+([-+.]\\w+)*@(\\w+([-.]\\w+)*\\.)+([a-zA-Z]+)+$", RegexOptions.IgnoreCase);
		return regex.Match(_value).Success;
	}
	public static bool IsMobileNum(string _value)
	{
		Regex regex = new Regex("^13\\d{9}$", RegexOptions.IgnoreCase);
		return regex.Match(_value).Success;
	}
	protected void Button_Ok_Click(object sender, EventArgs e)
	{
		if (this.CheckInput())
		{
			int ww_ID = Convert.ToInt32(this.WitkeyInfo["ww_ID"]);
			string ww_Email = this.TextBox_Email.Text.Trim();
			string ww_Phone = this.TextBox_Phone.Text.Trim();
			string ww_xsModel = string.Empty;
			string ww_Title = this.WitkeyTaskTitle.Text.Trim();
			string ww_Content = this.WitkeyContent.Text.Trim();
			string text = this.DropDownList_WitkeyTypeOne.SelectedItem.Text;
			string text2 = this.DropDownList_WitkeyTypeTwo.SelectedItem.Text;
			string ww_UserName = this.TextBox_Name.Text.Trim();
			if (this.WitkeyInfo["ww_Type"].ToString() == "1")
			{
				ww_xsModel = this.DropDownList_Mode.SelectedItem.Text;
			}
			Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
			shop_Witkey.UpdateWitkey(ww_ID, ww_Title, ww_Content, text, text2, ww_UserName, ww_xsModel, ww_Email, ww_Phone);
			this.WriteSuccessMsg("", Language.Get("Witkey/SaleWitkeySuccessUpdate"), "/Witkey/ShowWitkey.aspx?ww_ID=" + ww_ID.ToString());
		}
	}
}
